package com.frxuexi.sign

import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.lib_base.entity.SignBeanItem
import com.frxuexi.sign.databinding.ItemSignBinding

class SignAdapter:BaseQuickAdapter<SignBeanItem,BaseViewHolder>(R.layout.item_sign) {

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemSignBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: SignBeanItem) {
        val binding = DataBindingUtil.getBinding<ItemSignBinding>(helper.itemView)!!
        binding.bean=item
        var date=""
        var time=""
        if(item.morningCheckIn.isNotEmpty()){//上班卡
            val split = item.morningCheckIn.split(" ")
            date=split[0].replaceFirst("-","年").replaceFirst("-","月").plus("日")
            if(split.size>1) {
                time = "上班${split[1]}"
            }
        }else{
            val split = item.afternoonCheckIn.split(" ")
            date=split[0].replaceFirst("-","年").replaceFirst("-","月").plus("日")
            if(split.size>1) {
                time = "下班${split[1]}"
            }
        }
        binding.signDate.setText(date)
        binding.signTime.setText(time)

        binding.signStatus.apply {
            when(item.status){
                "正常"->{
                    setTextColor(context.getColor(com.frxuexi.lib_base.R.color.green))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_status)
                }
                "迟到"->{
                    setTextColor(context.getColor(com.frxuexi.lib_base.R.color.orange))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_weihu)
                }
                "早退"->{
                    setTextColor(context.getColor(com.frxuexi.lib_base.R.color.redfont))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_red)
                }
            }
        }
    }
}